package demo.game.chess.client.ui;

import demo.game.chess.common.AbstractChessPiece;
import demo.game.chess.common.ChessMove;
import demo.game.chess.common.ChessMoveMessage;
import demo.game.chess.common.ChessUndoMoveMessage;
import demo.messaging.client.core.ClientManager;

public class OnlineChessMoveListener implements IChessMoveListener {

	OnlineChessUI chessUI;

	public OnlineChessMoveListener(final OnlineChessUI chessUI) {
		this.chessUI = chessUI;
	}

	@Override
	public void afterConfirmMove(final AbstractChessUI chessUI,
			final AbstractChessPiece movingPiece, final ChessMove move) {

		ChessMoveMessage msg = new ChessMoveMessage(move);
		msg.setDestination(ClientManager.getClientManager()
				.getCurrentConnectedUser());
		ClientManager.getClientManager().sendMessageAsync(msg);
		this.chessUI.setEnabledUndo(false);

	}

	@Override
	public void afterUndoMove(final AbstractChessUI abstractChessUI) {
		ChessUndoMoveMessage msg = new ChessUndoMoveMessage();
		msg.setDestination(ClientManager.getClientManager()
				.getCurrentConnectedUser());
		ClientManager.getClientManager().sendMessageAsync(msg);
	}

	@Override
	public void beforeConfirmMove(final AbstractChessUI chessUI,
			final AbstractChessPiece movingPiece, final ChessMove move) {

	}

	@Override
	public void beforeUndoMove(final AbstractChessUI abstractChessUI) {

	}

}
